﻿/*******************************************************
* Copyright (c) 2018-2088, By XuXiang all rights reserved.
*
* FileName: FightInfo.h
* Summary: 战斗信息。
*
* Author: XuXiang
* Date: 2024-05-26 21:55
*******************************************************/

#ifndef __FightInfo_h__
#define __FightInfo_h__

#include <map>
#include <vector>
#include <string>
#include <Macro.h>
#include "FightDefine.h"
#include "FightFrameRecord.h"
using namespace std;

namespace Competition
{
	namespace Net
	{
		class SCFightOperateFrameNotify;
	}

	//战斗玩家信息
	class FightPlayerInfo
	{
	public:
		FightPlayerInfo(int user_id);

		//获取用户id
		inline const int GetUserID()const { return m_UserID; }
		//设置用户id
		inline void SetUserID(int uid) { m_UserID = uid; }

		//获取角色id
		inline const int GetRoleID()const { return m_RoleID; }
		//设置角色id
		inline void SetRoleID(int rid) { m_RoleID = rid; }

		//获取角色配置ID
		inline const int GetRoleConfigID()const { return m_RoleConfigID; }
		//设置角色配置ID
		inline void SetRoleConfigID(int cid) { m_RoleConfigID = cid; }

		//获取角色阵营
		inline const int GetCamp()const { return m_Camp; }
		//设置角色阵营
		inline void SetCamp(int camp) { m_Camp = camp; }

		//获取角色计算的胜利阵营
		inline const int GetWinCamp()const { return m_WinCamp; }
		//设置角色计算的胜利阵营
		inline void SetWinCamp(int camp) { m_WinCamp = camp; }

		//获取是否已确认
		inline const bool IsConfirm()const { return m_Confirm; }
		//设置是否已确认
		inline void SetConfirm(bool confirm) { m_Confirm = confirm; }

		//获取加载进度(千分比)
		inline const int GetLoadProgress()const { return m_LoadProgress; }
		//设置加载进度(千分比)
		inline void SetLoadProgress(int progress) { m_LoadProgress = progress; }

		//获取是否加载完毕
		inline const bool IsLoadOK()const { return m_LoadOK; }
		//设置是否加载完毕
		inline void SetLoadOK(bool ok) { m_LoadOK = ok; }

		//获取战斗状态
		inline const int GetState()const { return m_State; }
		//设置战斗状态
		inline void SetState(int state) { m_State = state; }

		//进行移动操作
		inline void DoMove(Int16 p1, Int16 p2) { m_IsMove = true; m_MoveP1 = p1; m_MoveP2 = p2; }

		//进行释放技能操作
		inline void DoSkillCast(int id, int p1, int p2) { m_IsSkillCast = true; m_SkillID = id; m_SkillP1 = p1; m_SkillP2 = p2; }

		//进行按下技能操作
		inline void DoSkillPress(int id) { m_IsSkillPress = true; m_SkillID = id; }

		//进行移动技能操作
		inline void DoSkillMove(int id, Int16 p1, Int16 p2) { m_IsSkillMove = true; m_SkillID = id; m_SkillP1 = p1; m_SkillP2 = p2; }

		//进行松开技能操作
		inline void DoSkillRelease(int id, Int16 p1, Int16 p2) { m_IsSkillRelease = true; m_SkillID = id; m_SkillP1 = p1; m_SkillP2 = p2; }

		//重置操作。
		inline void ResetOperate();

		//打包操作
		int PackOperate(Byte* buff, int index, int &op_num);

	private:

		//用户ID
		int m_UserID = 0;

		//角色ID
		int m_RoleID = 0;

		//角色配置ID
		int m_RoleConfigID = 0;

		//所属阵营
		int m_Camp = BelongCamp::None;

		//所计算的胜利阵营
		int m_WinCamp = BelongCamp::None;

		//是否已确认
		bool m_Confirm = false;

		//加载进度(千分比)
		int m_LoadProgress = 0;

		//是否加载完毕
		bool m_LoadOK = false;

		//战斗状态 0:未战斗 1:正常战斗 2:掉线中 3:重新计算 4:已退出
		int m_State = 0;

		//是否进行了移动操作
		bool m_IsMove = false;

		//移动参数1
		Int16 m_MoveP1 = 0;

		//移动参数2
		Int16 m_MoveP2 = 0;

		//是否释放技能
		bool m_IsSkillCast = false;

		//是否按下技能
		bool m_IsSkillPress = false;

		//是否技能移动
		bool m_IsSkillMove = false;

		//是否松开技能
		bool m_IsSkillRelease = false;

		//技能编号
		int m_SkillID = 0;

		//技能参数1
		Int32 m_SkillP1 = 0;

		//技能参数2
		Int32 m_SkillP2 = 0;
	};
	typedef map<int, FightPlayerInfo*> FightPlayerInfoMap;
	typedef vector<FightPlayerInfo*> FightPlayerInfoVector;

	void FightPlayerInfo::ResetOperate()
	{
		m_IsMove = false;
		m_IsSkillCast = false;
		m_IsSkillPress = false;
		m_IsSkillMove = false;
		m_IsSkillRelease = false;
	}

	//战斗组信息
	class FightGroupInfo
	{
	public:
		FightGroupInfo(int group_id);
		~FightGroupInfo();

		//获取组编号
		inline const int GetGroupID()const { return m_GroupID; }
		//设置组编号
		inline void SetGroupID(int group_id) { m_GroupID = group_id; }

		//获取战斗状态
		inline const int GetState()const { return m_State; }
		//设置战斗状态
		inline void SetState(int state) { m_State = state; }

		//获取准备时间秒
		inline const Int64 GetStartTime()const { return m_StartTime; }
		//设置准备时间秒
		inline void SetStartTime(Int64 time) { m_StartTime = time; }

		//获取随机种子
		inline const UInt32 GetRandSeed()const { return m_RandSeed; }
		//设置随机种子
		inline void SetRandSeed(UInt32 seed) { m_RandSeed = seed; }

		//获取帧索引
		inline const int GetFrameIndex()const { return m_FrameIndex; }
		//设置帧索引
		inline void SetFrameIndex(int index) { m_FrameIndex = index; }

		//获取胜利阵营
		inline const int GetWinCamp()const { return m_WinCamp; }
		//设置胜利阵营
		inline void SetWinCamp(int camp) { m_WinCamp = camp; }

		//添加匹配信息
		inline void AddPlayerInfo(FightPlayerInfo* info) { m_PlayerInfos.push_back(info); }

		//获取匹配信息列表
		inline FightPlayerInfoVector& GetPlayerInfos() { return m_PlayerInfos; }

		//获取用户信息
		FightPlayerInfo* GetPlayer(int user_id);

		//更新战斗帧
		void UpdateFightFrame(Net::SCFightOperateFrameNotify& ntf);

		//获取帧信息记录
		inline FightFrameRecord* GetFrameRecord() { return m_Recorder; }

	private:

		//组编号
		int m_GroupID;

		//战斗状态 0:未参与战斗 1:选角色 2:战斗加载 3:战斗中 4:已结束
		int m_State;

		//开始准备时间秒
		Int64 m_StartTime;

		//战斗随机种子
		UInt32 m_RandSeed = 0;

		//帧索引
		int m_FrameIndex;

		//胜利阵营
		int m_WinCamp = BelongCamp::None;

		//匹配信息列表
		FightPlayerInfoVector m_PlayerInfos;

		//战斗记录
		FightFrameRecord* m_Recorder = NULL;
	};
	typedef map<int, FightGroupInfo*> FightGroupMap;
	typedef vector<FightGroupInfo*> FightGroupVector;
}

#endif